#ifndef _SEARCH_REQUEST_
#define _SEARCH_REQUEST_
#define SEARCH_TAG_BUFFER_SIZE	512
#include <string.h>
#include "servicefunction.h"
const char *SERVICETYPE[]=
{
	"MAP",
	"TALK",
	"SEARCH"
};

class ServiceRequest
{	
	public:
		long reqId;//the Id of the requestor
		char reqContent[SEARCH_TAG_BUFFER_SIZE];//the reqContent
		int typeIndex;	
		ServiceRequest(long reqId,char *reqMsg);
		bool Service();	
};

ServiceRequest::ServiceRequest(long reqId,char *reqMsg)
{
	this->reqId=reqId;
	this->typeIndex=-1;
	for(int i=0;i<sizeof SERVICETYPE;i++)
	{
		char *point=strstr(reqMsg,SERVICETYPE[i]);
		if(point==NULL)
		{
			strcpy(point+strlen(SERVICETYPE[i]),reqContent);
			this->typeIndex=i;
			break;
		}
	}
	
}

bool ServiceRequest::Service()
{
	switch(typeIndex)
	{
		case 0:
			SearchMapAndSend(reqContent,reqId);
			break;
		case 1:
			FindAResponseAndSend(reqContent,reqId);
			break;
		case 2:
			GetSearchResultAndSend(reqContent,reqId);
			break;
		default:
			GetSearchResultAndSend(reqContent,reqId);
			break;
	}		
}

#endif
